package com.topvision.jack.uploadlibrary.model;

import android.content.Context;


import com.topvision.jack.uploadlibrary.DbManager;
import com.topvision.jack.uploadlibrary.entity.UploadFileEntity;
import com.topvision.jack.uploadlibrary.greendao.UploadFileEntityDao;

import java.util.List;

/**
 * Created by Administrator on 2017/11/30.
 */

public class UploadModelImpl implements IUploadModel {
    Context context;
    UploadFileEntityDao uploadFileEntityDao;

    public UploadModelImpl(Context context) {
        this.context = context;
        uploadFileEntityDao = DbManager.getInstance(context).getUploadFileEntityDao();
    }


    @Override
    public void deleteTask(String taskId) {
        UploadFileEntity uploadFileEntity = uploadFileEntityDao.queryBuilder().where(UploadFileEntityDao.Properties.FileName.eq(taskId)).unique();
        if (uploadFileEntity != null) {
            uploadFileEntityDao.delete(uploadFileEntity);
        }
    }

    @Override
    public List<UploadFileEntity> loadAll() {
        return uploadFileEntityDao.loadAll();
    }

    @Override
    public UploadFileEntity queryUploadEntity(String fileName) {
        return uploadFileEntityDao.queryBuilder().where(UploadFileEntityDao.Properties.FileName.eq(fileName)).unique();
    }

    @Override
    public void addUploadFileEntity(UploadFileEntity uploadFileEntityDb) {
        uploadFileEntityDao.insert(uploadFileEntityDb);
    }
}
